﻿//添加到收藏夹中
function addFavorite(site_url,site_name)
{
    var the_pagetitle=site_name;
    var the_pageurl=site_url;
    if(the_pageurl=="")
    {
        the_pageurl=window.location.href;
    }
    if(the_pagetitle=="")
    {   
        the_pagetitle=document.title;
    }
    try
    {
        window.external.addFavorite(the_pageurl,the_pagetitle);
    }
    catch(e)
    {
        try
        {
            window.sidebar.addPanel(the_pagetitle,the_pageurl,"");
        }
        catch(e)
        {
            alert("Sorry, the browser you are using cannot complete this operation。\n\nfailed to join the collection. Please use Ctrl+D to add!");
        }
    }
}

//将该网站设为主页
function setHomePage(site_url)
{
    var the_pageurl=site_url;
    if(the_pageurl=="")
    {
        the_pageurl=window.location.href;
    }
    try
    {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(the_pageurl);
    }
    catch(e) 
    {
        if(window.netscape){
            try{
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
            }catch (e){
                alert( "The browser operation is refused, if you want to enable this feature, please enter the about:config address bar, and then the signed.applets.codebase_principal_support value is true" );
            }
        }
        else
        {
            alert("Sorry, the browser you are using cannot complete this operation.\n\nYou need to manually set 【" + the_pageurl + "】 to the home page.");
        }
        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
        prefs.setCharPref('browser.startup.homepage',the_pageurl);
    }
}